package servit;

import java.io.IOException;
import java.util.Date;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import dao.tbldao;
import enily.tbl;
import seriver.tblimpl;

@WebServlet(urlPatterns = "/add.shtml")
public class addservit extends HttpServlet {

	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		req.setCharacterEncoding("UTF-8");
		tbldao rai = new tblimpl();
		String message = req.getParameter("message");
		String author = req.getParameter("author");
		
		
		
		tbl t = new tbl();
		t.setAuthor(author);
		t.setMessage(message);
		t.setPostTime(new Date());
		int sum = rai.add(t);
		if (sum > 0) {
			resp.sendRedirect("/PingLun/index.shtml");
		}

	}

	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		this.doGet(req, resp);
	}

}
